package com.acaomei.skype.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.acaomei.skype.common.Result;
import com.acaomei.skype.common.ResultVo;
import com.acaomei.skype.entity.User;
import com.acaomei.skype.service.IUserService;
import com.acaomei.skype.util.PagedResult;

@Controller    
@RequestMapping("/user") 
public class UserController {
	private Log log = LogFactory.getLog(UserController.class);
	private Log payLog = LogFactory.getLog("payLog");
	@Resource
	private IUserService userService;
	
	@RequestMapping("/getUserList")
    public String getUserList(User user,Integer pageNo,Integer pageSize,ModelMap modelMap){ 
		//log.info("===========你好！=========");
		log.error("================hahah=================");
		payLog.info("===========测试info！=========");
		payLog.error("===========测试error！=========");
        PagedResult<User> pageResult = userService.getAllUser(user, pageNo,pageSize);
		modelMap.addAttribute("pageResult", pageResult);
		return "user/userManage";
    }
	
	@ResponseBody
	@RequestMapping(value="/getUserInfoList", method=RequestMethod.GET)
    public Result<List<User>> getUserInfoList(User user,Integer pageNo,Integer pageSize){ 
        PagedResult<User> pageResult = userService.getAllUser(user, pageNo,pageSize);
		return ResultVo.successResult(String.valueOf(pageResult.getTotal()),pageResult.getDataList());
    }
	
	@ResponseBody
	@RequestMapping(value="/addUserInfo", method=RequestMethod.POST)
    public Result<String> addUserInfo(){ 
		User user = new User();
		user.setUserName("test");
		user.setUserEmail("1346559164@qq.com");
		user.setUserPassword("wh123456");
		return userService.addUserInfo(user);
    }
	
	@ResponseBody
	@RequestMapping(value="/addBatchUserInfo", method=RequestMethod.POST)
    public Result<String> addBatchUserInfo(){ 
		List<User> userList = new ArrayList<>();
		User user = new User();
		user.setUserName("test");
		user.setUserEmail("1346559164@qq.com");
		user.setUserPassword("wh123456");
		userList.add(user);
		
		user = new User();
		user.setUserName("张山");
		user.setUserEmail("1346559164@qq.com");
		user.setUserPassword("wh123456");
		userList.add(user);
		
		user = new User();
		user.setUserName("123");
		user.setUserEmail("1346559164@qq.com");
		user.setUserPassword("wh123456");
		userList.add(user);
		return userService.addBatchUserInfo(userList);
    }
	
}
